Only disallow hyphens in lib target names
authorAlex Crichton <alex@alexcrichton.com>
Wed, 25 Mar 2015 17:20:50 +0000 (10:20 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 25 Mar 2015 23:08:46 +0000 (16:08 -0700)
Examples, tests, binaries, etc, are all allowed to have hyphens (cargo does some
renaming internally).

Close #1450

src/cargo/util/toml.rs

index 23d255b79b5cc791e3cb94e27d5d58501a3fb2e3..debe90e37b881dd6e0b42713b635f0c2348216d2 100644 (file)
@@ -396,7 +396,7 @@ impl TomlManifest {
                     _ => {}
                 }
                 try!(libs.as_slice().iter().map(|t| {
-                    try!(validate_target_name(t));
+                    try!(validate_library_name(t));
                     Ok(if layout.lib.is_some() && t.path.is_none() {
                         TomlTarget {
                             path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())),
@@ -414,48 +414,36 @@ impl TomlManifest {
             Some(ref bins) => {
                 let bin = layout.main();
 
-                try!(bins.iter().map(|t| {
-                    try!(validate_target_name(t));
-                    Ok(if bin.is_some() && t.path.is_none() {
+                bins.iter().map(|t| {
+                    if bin.is_some() && t.path.is_none() {
                         TomlTarget {
                             path: bin.as_ref().map(|&p| PathValue::Path(p.clone())),
                             .. t.clone()
                         }
                     } else {
                         t.clone()
-                    })
-                }).collect::<CargoResult<Vec<_>>>())
+                    }
+                }).collect()
             }
             None => inferred_bin_targets(&project.name, layout)
         };
 
         let examples = match self.example {
-            Some(ref examples) => {
-                for example in examples {
-                    try!(validate_target_name(example));
-                }
-                examples.clone()
-            }
+            Some(ref examples) => examples.clone(),
             None => inferred_example_targets(layout),
         };
 
         let tests = match self.test {
-            Some(ref tests) => {
-                for test in tests {
-                    try!(validate_target_name(test));
-                }
-                tests.clone()
-            }
+            Some(ref tests) => tests.clone(),
             None => inferred_test_targets(layout),
         };
 
         let benches = if self.bench.is_none() || self.bench.as_ref().unwrap().is_empty() {
             inferred_bench_targets(layout)
         } else {
-            try!(self.bench.as_ref().unwrap().iter().map(|t| {
-                try!(validate_target_name(t));
-                Ok(t.clone())
-            }).collect::<CargoResult<Vec<_>>>())
+            self.bench.as_ref().unwrap().iter().map(|t| {
+                t.clone()
+            }).collect()
         };
 
         // processing the custom build script
@@ -544,9 +532,9 @@ impl TomlManifest {
     }
 }
 
-fn validate_target_name(target: &TomlTarget) -> CargoResult<()> {
+fn validate_library_name(target: &TomlTarget) -> CargoResult<()> {
     if target.name.contains("-") {
-        Err(human(format!("target names cannot contain hyphens: {}",
+        Err(human(format!("library target names cannot contain hyphens: {}",
                           target.name)))
     } else {
         Ok(())